import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {SignupService} from '../signup.service';
import {SignupSetting} from '../signup-setting';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-signsetting',
    templateUrl: './signsetting.component.html',
})
export class SignsettingComponent implements OnInit {
    total = 0;
    pagesize = 10;
    pageCurrent = 1;
    data: SignupSetting[] = [];

    constructor(
        private signService: SignupService,
        private msg: NzMessageService
    ) {
    }

    ngOnInit() {
        this.getlist(this.pageCurrent - 1);
    }

    getlist($event) {

        this.signService.settingList().subscribe(res => {
            this.data = res['list'];
            this.total = res['totalElement'];
            this.pagesize = res['pageSize'];
            this.pageCurrent = $event;
        });
    }

    del(item) {
        const index = this.data.indexOf(item);
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.signService.delSignupSetting(item['id']).subscribe(res => {
            this.msg.success('删除成功');
        }, __ => {
            this.signService.settingList();
        });
    }
}
